// pages/room/room.js
//	创建 live-pusher 上下文 LivePusherContext 对象。
var pushContext = wx.createLivePusherContext()


Page({
  /**
   * 页面的初始数据
   */
  data: {
    // player  别人的
    muted: false, //muted   boolean	false	否	是否静音
    soundMode: 'speaker', // sound-mode  string	speaker	扬声器  ear	否	声音输出方式
    // pusher  自己的
    enableMic: true, // enable-mic	boolean	true	否	开启或关闭麦克风
    allData: null, // 推拉流地址
    enableCamera: false, //摄像头

    from: null, //来源
    ready: false
  },
  // 切换扬声器
  toggleVolume() {
    var soundMode = this.data.soundMode
    if (soundMode == 'speaker') {
      this.setData({
        soundMode: 'ear'
      })
      wx.showToast({
        icon: "none",
        title: "关闭扬声器"
      })
    }
    if (soundMode == 'ear') {
      this.setData({
        soundMode: 'speaker'
      })
      wx.showToast({
        icon: "none",
        title: "打开扬声器"
      })
    }
  },
  // 切换我的声音
  toggleMic() {
    var enableMic = this.data.enableMic
    if (enableMic == true) {
      this.setData({
        enableMic: false
      })
      wx.showToast({
        icon: "none",
        title: "关闭麦克风"
      })
    }
    if (enableMic == false) {
      this.setData({
        enableMic: true
      })
      wx.showToast({
        icon: "none",
        title: "打开麦克风"
      })
    }
  },
  // 挂电话
  onPhoneTab() {
    wx.navigateBack()
  },
  statechangepush(e) {
    console.log('live-pusher', e);
    // wx.showToast({
    //   icon: "none",
    //   title: e.detail.message
    // })
    // console.log(e.detail.message);


  },
  statechangeplayer(e) {
    // wx.showLoading({
    //   title: '等待连接中...',
    // })
    // console.log('live-player', e);
    wx.showToast({
      icon: "none",
      title: e.detail.message
    })
    console.log(e.detail.message);

    if (e.detail.code == -2301) {
      // wx.hideLoading()
      wx.showToast({
        icon: "none",
        title: "对方离线/未上线",
        success: () => {
          setTimeout(() => {
            wx.navigateBack()
          }, 1500)
        }
      })
    }else{
      // wx.hideLoading()
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options', options);
    var from = options.from
    this.setData({
      from: from
    })


    // imgUrl: "https://ywpd-picture.obs.cn-east-2.myhuaweicloud.com:443/photo/838804127-1_photo.png?AccessKeyId=TEPZ5RHAPORK7NWI4AI9&Expires=1697780726&Signature=MxHjVis2VhFWnjr%2FmuWJ41DP6vU%3D"
    // pushUrl: "rtmp://pili-publish.52yuze.com/ywpd/1603704335029"
    // creatTime: "2020-10-26 17:25:35"
    // orderId: 91
    // pullUrl1: "rtmp://pili-live-rtmp.52yuze.com/ywpd/1603704335030"
    // pushUrl1: "rtmp://pili-publish.52yuze.com/ywpd/1603704335030"
    // roomId: 1603704335029
    // roomName: "开黑语音"
    // pullUrl: "rtmp://pili-live-rtmp.52yuze.com/ywpd/1603704335029"


    // var data = {
    //   imgUrl: options.imgUrl,
    //   pushUrl: options.pullUrl,
    //   pullUrl: options.pushUrl
    // }
    // console.log('datadatadatadatadata', data);
    // this.setData({
    //   allData: data
    // })



    var data = wx.getStorageSync('voice')
    console.log('datadatadatadatadata', data);
    this.setData({
      allData: data
    })





  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      ready: true
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.removeStorageSync('voice')
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})